package utils;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by guo on 2017/11/11.
 */
public class ControllerUtils {
    //获得包下面的所有的类对象
    public static List<Class> getAllClass(String packName) throws ClassNotFoundException {
        List<Class> list=new ArrayList();
        String pagePath=packName.replace(".","/");
        URL url=Thread.currentThread().getContextClassLoader().getResource(pagePath);
        String filePath=url.getPath();
        File file=new File(filePath);
        File[] files=file.listFiles();
        for (File f:files){
            String fileName=f.getName();
            //对名字做处理，去掉扩展名.class net.zjitc.controller.ProductController
            String clazzName =packName+"."+fileName.substring(0,fileName.length()-6);
            Class clazz=Class.forName(clazzName);
            list.add(clazz);
        }


        return list;
    }
}
